package 力扣日常刷题.木22二月.第22天228;

/**
 * @author 帅小伙
 * @date 2022/2/28
 * @description
 */
public class Demo179最大连续1的个数III {


    public static void main(String[] args) {
        int[] arr = new int[]{1,1,1,0,0,0,1,1,1,1,0};
        longestOnes(arr,2);
    }

    public static int longestOnes(int[] nums, int k) {
        int l = 0, r = 0;

        while(r < nums.length) {
            if(nums[r++] == 0) k--;
            if(k <0 && nums[l++] == 0) k++;
        }
        return r - l;
    }

}
